# Maintainer: Philipp Smirnov https://github.com/sad-poet

_realname=ada_language_server
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
pkgver=25.0.0
pkgrel=2
pkgdesc="Server implementing the Microsoft Language Server Protocol (LSP) for Ada and SPARK (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64')
url="https://github.com/AdaCore/ada_language_server"
msys2_references=(
  'aur: ada_language_server'
  'gentoo: dev-ada/ada_language_server'
)
license=('spdx:GPL-3.0-or-later')
makedepends=("${MINGW_PACKAGE_PREFIX}-gprbuild"
             "${MINGW_PACKAGE_PREFIX}-python")
depends=("${MINGW_PACKAGE_PREFIX}-ada_spawn"
         "${MINGW_PACKAGE_PREFIX}-ada-libfswatch"
         "${MINGW_PACKAGE_PREFIX}-gcc-ada"
         "${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-gnatcoll-core"
         "${MINGW_PACKAGE_PREFIX}-gnatcoll-gmp"
         "${MINGW_PACKAGE_PREFIX}-gnatcoll-iconv"
         "${MINGW_PACKAGE_PREFIX}-gnatdoc"
         "${MINGW_PACKAGE_PREFIX}-gnatformat"
         "${MINGW_PACKAGE_PREFIX}-gpr"
         "${MINGW_PACKAGE_PREFIX}-lal-refactor"
         "${MINGW_PACKAGE_PREFIX}-libadalang"
         "${MINGW_PACKAGE_PREFIX}-libadalang-tools"
         "${MINGW_PACKAGE_PREFIX}-libgpr"
         "${MINGW_PACKAGE_PREFIX}-libvss"
         "${MINGW_PACKAGE_PREFIX}-prettier-ada"
         "${MINGW_PACKAGE_PREFIX}-xmlada")
source=("https://github.com/AdaCore/ada_language_server/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('105807ebfb39fcf35f99a6cf321d0b28ff246d7e6443fccce258deea1aefa7c4')

build() {
  [[ -d "${srcdir}"/build-${MSYSTEM} ]] && rm -rf "${srcdir}"/build-${MSYSTEM}
  cp -r "${srcdir}/${_realname}-${pkgver}" "${srcdir}"/build-${MSYSTEM}
  cd "${srcdir}"/build-${MSYSTEM}

  make \
    BUILD_MODE=prod \
    LIBRARY_TYPE=relocatable \
    VERSION="${pkgver}" \
    BUILD_DATE="$(LANG=C date '+%Y%m%d')"

  LIBRARY_TYPE=relocatable \
  gprbuild gnat/lsp_client_glib.gpr
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}

  make install \
    prefix="${pkgdir}${MINGW_PREFIX}" \
    BUILD_MODE=prod \
    LIBRARY_TYPE=relocatable

  LIBRARY_TYPE=relocatable \
  gprinstall --prefix="${pkgdir}${MINGW_PREFIX}" -p gnat/lsp_client_glib.gpr

  rm -fv "${pkgdir}"${MINGW_PREFIX}/share/gpr/gnatcoll.gpr
  rm -fv "${pkgdir}"${MINGW_PREFIX}/share/gpr/manifests/gnatcoll

  install -Dm644 -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}" \
    "${srcdir}/${_realname}-${pkgver}"/LICENSE
}
